# SkyWalking 数据采集与分析系统 Docker 镜像
FROM continuumio/miniconda3:latest

# 设置工作目录
WORKDIR /app

# 安装系统工具（使用默认 Debian 官方源）
# 配置 apt 使用阿里云镜像源并安装系统工具（修正 security 源）
RUN echo "deb https://mirrors.aliyun.com/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
    echo "deb https://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
    echo "deb https://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
    rm -f /etc/apt/sources.list.d/* && \
    apt-get update && apt-get install -y \
    vim \
    git \
    curl \
    wget \
    build-essential \
    openssh-client \
    && rm -rf /var/lib/apt/lists/*

# 安装 Git LFS
RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash && \
    apt-get update && apt-get install -y git-lfs && \
    git lfs install && \
    rm -rf /var/lib/apt/lists/*

# 配置 Git 用户信息
RUN git config --global user.email "gaoyu.ssdut@icloud.com" && \
    git config --global user.name "gaoyussdut"

# 创建 SSH 目录并添加密钥
RUN mkdir -p /root/.ssh && chmod 700 /root/.ssh

# 添加 SSH 私钥
RUN echo '-----BEGIN OPENSSH PRIVATE KEY-----' > /root/.ssh/id_ed25519 && \
    echo 'b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW' >> /root/.ssh/id_ed25519 && \
    echo 'QyNTUxOQAAACA9wMmnFncu1tMwTqqF3mjiYpE/wJKaDd+RWp/tTPA1UQAAAKDEvxagxL8W' >> /root/.ssh/id_ed25519 && \
    echo 'oAAAAAtzc2gtZWQyNTUxOQAAACA9wMmnFncu1tMwTqqF3mjiYpE/wJKaDd+RWp/tTPA1UQ' >> /root/.ssh/id_ed25519 && \
    echo 'AAAEA/A6uuTXUkUbwkOQq+yprYXlnfGNzrmN2IWoQpoO7Ouz3AyacWdy7W0zBOqoXeaOJi' >> /root/.ssh/id_ed25519 && \
    echo 'kT/AkpoN35Fan+1M8DVRAAAAFmdhb3l1LnNzZHV0QGljbG91ZC5jb20BAgMEBQYH' >> /root/.ssh/id_ed25519 && \
    echo '-----END OPENSSH PRIVATE KEY-----' >> /root/.ssh/id_ed25519 && \
    chmod 600 /root/.ssh/id_ed25519

# 添加 SSH 公钥
RUN echo 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID3AyacWdy7W0zBOqoXeaOJikT/AkpoN35Fan+1M8DVR gaoyu.ssdut@icloud.com' > /root/.ssh/id_ed25519.pub && \
    chmod 644 /root/.ssh/id_ed25519.pub

# 配置 SSH 客户端
RUN echo 'Host *' > /root/.ssh/config && \
    echo '    StrictHostKeyChecking no' >> /root/.ssh/config && \
    echo '    UserKnownHostsFile=/dev/null' >> /root/.ssh/config && \
    chmod 600 /root/.ssh/config

# 配置 conda 使用清华镜像源
RUN conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main && \
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free && \
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge && \
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch && \
    conda config --set show_channel_urls yes && \
    conda config --set channel_priority strict

# 创建并激活 Python 3.11 环境
RUN conda create -n skywalking python=3.11 -y && \
    conda clean -afy

# 将 conda 环境添加到 PATH
ENV PATH /opt/conda/envs/skywalking/bin:$PATH

# 复制项目文件
COPY requirements.txt /app/
COPY environment.yml /app/

# 安装 Python 依赖
RUN /opt/conda/envs/skywalking/bin/pip install --no-cache-dir -r requirements.txt

# 复制应用代码
COPY . /app/

# 创建数据目录
RUN mkdir -p /app/data /app/logs

# 设置环境变量
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app

# 暴露端口
EXPOSE 8501

# 默认命令（可通过 docker-compose 覆盖）
CMD ["/bin/bash"]

